package com.weidft.biz.encrypt;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class PasswordUtils {

    private PasswordUtils() {
    }

    /**
     * Digests the password via SHA.
     */
    public static String digestPassword(String password) {
    	if (password==null)
    	{
    		return null;
    	}
        try {
            MessageDigest digester = MessageDigest.getInstance("SHA");
            byte[] digest = digester.digest(password.getBytes("UTF-8"));
            return Base64.encode(digest);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("SHA digest algorithm is not supported in this JVM.");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 encoding is not supported in this JVM.");
        }
    }
}
